package com.example.deploysinggle.test1.common.util;

import javax.swing.text.DateFormatter;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

/**
 * @author Administrator
 * @version 1.0
 * @description: TODO
 * @date 2024/12/27 15:56
 */
public class DateUtil {
    // 转换格式
    public static final String  EEE_MMM_DD_HH_MM_SS_Z_YYYY = "EEE MMM dd HH:mm:ss Z yyyy";
    // 把Mon Jan 01 12:00:00 PST 2023 字符串类型的日期转化成自定义 类型日期的字符串
    public  static  String translateStrDate(String dateStr, String formatStr){
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(EEE_MMM_DD_HH_MM_SS_Z_YYYY)
                .withLocale(Locale.US);
        ZonedDateTime parse = ZonedDateTime.parse(dateStr, dateTimeFormatter);
        DateTimeFormatter newFormatter = DateTimeFormatter.ofPattern(formatStr);
        return newFormatter.format(parse);

    }
}
